﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Hoo.Windows.Shell.Util;

namespace Hoo.Windows.Shell.Menu {

    /// <summary>
    /// Defines "Copy full path" menu.
    /// When user clicks this menu, the selected file/folder's full file name with path will be sent to clipboard.
    /// If user selects more than one file/folder, All file/folder's full path will be copied, per file/folder per line.
    /// If user does not select any file/folder, in other words, user right click empty area of explorer, parent folder's full path will be copied. 
    /// </summary>
    public class CopyFullPath : MenuItem {
        public CopyFullPath()
            : base() {
            Title = "Copy Full Path";            
        }

        public CopyFullPath(int id)
            : this() {
            ID = id;
        }

        public override void Execute(string currentDirectory, IList<string> selectedFiles) {
            StringBuilder sb = new StringBuilder();

            if (selectedFiles != null && selectedFiles.Count >= 1) {
                foreach (string file in selectedFiles) {
                    sb.AppendLine(file);
                }
            } else {
                sb.Append(currentDirectory);
            }

            try {
                Clipboard.Clear();
                Clipboard.SetText(sb.ToString());
            } catch (Exception ex) {
                Logger.Error(ex);
            }
        }
        
    }

    /// <summary>
    /// Defines "Copy File Name" menu.
    /// This menu is similar with <code>CopyFullPath</code>, but only sent files/folders name without path to clipboard
    /// </summary>
    public class CopyFileName : MenuItem {
        public CopyFileName()
            : base() {
            Title = "Copy File Name Without Path";
        }

        public CopyFileName(int id)
            : this() {
            ID = id;
        }

        public override void Execute(string currentDirectory, IList<string> selectedFiles) {
            StringBuilder sb = new StringBuilder();

            if (selectedFiles != null && selectedFiles.Count >= 1) {
                foreach (string file in selectedFiles) {
                    sb.AppendLine(file.Substring(file.LastIndexOf('\\') + 1));
                }
            }

            try {
                Clipboard.Clear();
                Clipboard.SetText(sb.ToString());
            } catch (Exception ex) {
                Logger.Info(ex.ToString());
            }
        }

    }
}
